/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('ekyc-saas', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model FaceRecognitionCompareRequest {
  idCardImageData?: string(name='idCardImageData', example='/9j/4AAQSkZJRgABAQEAXgBeAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL******'),
  idCardImageType?: string(name='idCardImageType', example='pic'),
  idCardImageUrl?: string(name='idCardImageUrl', example='https://your_test_image.jpg'),
  portraitImageData?: string(name='portraitImageData', example='/9j/4AAQSkZJRgABAQEAXgBeAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL******'),
  portraitImageType?: string(name='portraitImageType', example='pic'),
  portraitImageUrl?: string(name='portraitImageUrl', example='https://your_test_image.jpg'),
  qualityControl?: string(name='qualityControl', example='NONE'),
}

model FaceRecognitionCompareResponseBody = {
  code?: string(name='Code', example='0'),
  data?: {
    match?: string(name='Match', example='pass'),
    score?: double(name='Score', example='60.8'),
  }(name='Data'),
  httpCode?: long(name='HttpCode', example='200'),
  message?: string(name='Message', example='null'),
  ok?: boolean(name='Ok', example='true'),
  requestId?: string(name='RequestId', example='4D93120B-9A81-11F5-8307-B746390C644D'),
  status?: string(name='Status', example='SUCCESS'),
}

model FaceRecognitionCompareResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: FaceRecognitionCompareResponseBody(name='body'),
}

async function faceRecognitionCompareWithOptions(request: FaceRecognitionCompareRequest, headers: map[string]string, runtime: Util.RuntimeOptions): FaceRecognitionCompareResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.idCardImageData)) {
    body['idCardImageData'] = request.idCardImageData;
  }
  if (!Util.isUnset(request.idCardImageType)) {
    body['idCardImageType'] = request.idCardImageType;
  }
  if (!Util.isUnset(request.idCardImageUrl)) {
    body['idCardImageUrl'] = request.idCardImageUrl;
  }
  if (!Util.isUnset(request.portraitImageData)) {
    body['portraitImageData'] = request.portraitImageData;
  }
  if (!Util.isUnset(request.portraitImageType)) {
    body['portraitImageType'] = request.portraitImageType;
  }
  if (!Util.isUnset(request.portraitImageUrl)) {
    body['portraitImageUrl'] = request.portraitImageUrl;
  }
  if (!Util.isUnset(request.qualityControl)) {
    body['qualityControl'] = request.qualityControl;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'FaceRecognitionCompare',
    version = '2023-01-12',
    protocol = 'HTTPS',
    pathname = `/face_recognition_compare`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function faceRecognitionCompare(request: FaceRecognitionCompareRequest): FaceRecognitionCompareResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return faceRecognitionCompareWithOptions(request, headers, runtime);
}

model FaceToFaceCompareRequest {
  portraitImageData1?: string(name='portraitImageData1', example='/9j/4AAQSkZJRgABAQEAXgBeAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL******'),
  portraitImageData2?: string(name='portraitImageData2', example='/9j/4AAQSkZJRgABAQEAXgBeAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL******'),
  portraitImageType1?: string(name='portraitImageType1', example='pic'),
  portraitImageType2?: string(name='portraitImageType2', example='pic'),
  portraitImageUrl1?: string(name='portraitImageUrl1', example='https://your_test_image.jpg'),
  portraitImageUrl2?: string(name='portraitImageUrl2', example='https://your_test_image.jpg'),
  qualityControl?: string(name='qualityControl', example='NONE'),
}

model FaceToFaceCompareResponseBody = {
  code?: string(name='Code', example='0'),
  data?: {
    match?: string(name='Match', example='pass'),
    score?: double(name='Score', example='60.8'),
  }(name='Data'),
  httpCode?: long(name='HttpCode', example='200'),
  message?: string(name='Message', example='null'),
  ok?: boolean(name='Ok', example='true'),
  requestId?: string(name='RequestId', example='4D93120B-9A81-11F5-8307-B746390C644D'),
  status?: string(name='Status', example='SUCCESS'),
}

model FaceToFaceCompareResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: FaceToFaceCompareResponseBody(name='body'),
}

async function faceToFaceCompareWithOptions(request: FaceToFaceCompareRequest, headers: map[string]string, runtime: Util.RuntimeOptions): FaceToFaceCompareResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.portraitImageData1)) {
    body['portraitImageData1'] = request.portraitImageData1;
  }
  if (!Util.isUnset(request.portraitImageData2)) {
    body['portraitImageData2'] = request.portraitImageData2;
  }
  if (!Util.isUnset(request.portraitImageType1)) {
    body['portraitImageType1'] = request.portraitImageType1;
  }
  if (!Util.isUnset(request.portraitImageType2)) {
    body['portraitImageType2'] = request.portraitImageType2;
  }
  if (!Util.isUnset(request.portraitImageUrl1)) {
    body['portraitImageUrl1'] = request.portraitImageUrl1;
  }
  if (!Util.isUnset(request.portraitImageUrl2)) {
    body['portraitImageUrl2'] = request.portraitImageUrl2;
  }
  if (!Util.isUnset(request.qualityControl)) {
    body['qualityControl'] = request.qualityControl;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'FaceToFaceCompare',
    version = '2023-01-12',
    protocol = 'HTTPS',
    pathname = `/face_to_face_compare`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function faceToFaceCompare(request: FaceToFaceCompareRequest): FaceToFaceCompareResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return faceToFaceCompareWithOptions(request, headers, runtime);
}

model IdDetectOcrCompareFacesRequest {
  OCR?: boolean(name='OCR', example='false'),
  unrepeat?: boolean(name='Unrepeat', example='false'),
  cardDetect?: boolean(name='cardDetect', example='false'),
  countryCode?: string(name='countryCode', example='JPN'),
  documentType?: string(name='documentType', example='IDENTITY_CARD'),
  faceCompare?: boolean(name='faceCompare', example='false'),
  imageAType?: string(name='imageAType', example='pic'),
  imageBType?: string(name='imageBType', example='pic'),
  imageDataA?: string(name='imageDataA', example='/9j/4AAQSkZJRgABAQEAXgBeAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL******'),
  imageDataB?: string(name='imageDataB', example='/9j/4AAQSkZJRgABAQEAXgBeAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL******'),
  imageUrlA?: string(name='imageUrlA', example='https://your_test_image.jpg'),
  imageUrlB?: string(name='imageUrlB', example='https://your_test_image.jpg'),
  portraitImageData?: string(name='portraitImageData', example='/9j/4AAQSkZJRgABAQEAXgBeAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL******'),
  portraitImageUrl?: string(name='portraitImageUrl', example='https://your_test_image.jpg'),
  qualityControl?: string(name='qualityControl', example='NONE'),
}

model IdDetectOcrCompareFacesResponseBody = {
  code?: string(name='Code', example='0'),
  data?: {
    compareResult?: {
      code?: string(name='Code', example='0'),
      compareResultData?: {
        match?: string(name='Match', example='examine'),
        risks?: [ string ](name='Risks'),
        score?: double(name='Score', example='99.73'),
      }(name='CompareResultData'),
      message?: string(name='Message', example='null'),
    }(name='CompareResult'),
    idDetectResult?: {
      code?: string(name='Code', example='0'),
      idDetectResultData?: {
        antiSpoofingResult?: {
          passed?: boolean(name='Passed', example='false'),
          risks?: [ string ](name='Risks'),
        }(name='AntiSpoofingResult'),
        countryCode?: string(name='CountryCode', example='JPN'),
        detectionResult?: {
          cardRectangle?: [ long ](name='CardRectangle'),
          height?: long(name='Height', example='382'),
          portraitRectangle?: [ long ](name='PortraitRectangle'),
          width?: long(name='Width', example='600'),
        }(name='DetectionResult'),
        documentType?: string(name='DocumentType', example='IDENTITY_CARD'),
        passed?: boolean(name='Passed', example='true'),
        warning?: [ string ](name='Warning'),
      }(name='IdDetectResultData'),
      message?: string(name='Message', example='null'),
    }(name='IdDetectResult'),
    livenessResult?: {
      code?: string(name='Code'),
      livenessResultData?: {
        liveness?: string(name='Liveness'),
        risks?: [ string ](name='Risks'),
        score?: double(name='Score'),
      }(name='LivenessResultData'),
      message?: string(name='Message'),
    }(name='LivenessResult'),
    ocrResult?: {
      code?: string(name='Code', example='0'),
      message?: string(name='Message', example='null'),
      ocrResultData?: {
        address?: string(name='Address', example='null'),
        addressConfidence?: double(name='AddressConfidence', example='0.92'),
        addressPosition?: [ long ](name='AddressPosition'),
        dateOfBirth?: string(name='DateOfBirth', example='2009-01-16'),
        dateOfBirthConfidence?: double(name='DateOfBirthConfidence', example='0.92'),
        dateOfBirthPosition?: [ long ](name='DateOfBirthPosition'),
        documentNumber?: string(name='DocumentNumber', example='null'),
        documentNumber2?: string(name='DocumentNumber2', example='null'),
        documentNumber2Confidence?: double(name='DocumentNumber2Confidence', example='0.92'),
        documentNumber2Position?: [ long ](name='DocumentNumber2Position'),
        documentNumberConfidence?: double(name='DocumentNumberConfidence', example='0.92'),
        documentNumberPosition?: [ long ](name='DocumentNumberPosition'),
        expirationDate?: string(name='ExpirationDate', example='2027.01.16'),
        expirationDateConfidence?: double(name='ExpirationDateConfidence', example='0.92'),
        expirationDatePosition?: [ long ](name='ExpirationDatePosition'),
        firstName?: string(name='FirstName', example='null'),
        firstNameConfidence?: double(name='FirstNameConfidence', example='0.92'),
        firstNamePosition?: [ long ](name='FirstNamePosition'),
        fullName?: string(name='FullName', example='null'),
        fullNameConfidence?: double(name='FullNameConfidence', example='0.92'),
        fullNamePosition?: [ long ](name='FullNamePosition'),
        issuedDate?: string(name='IssuedDate', example='Jan 01 2023'),
        issuedDateConfidence?: double(name='IssuedDateConfidence', example='0.92'),
        issuedDatePosition?: [ long ](name='IssuedDatePosition'),
        issuingAuthority?: string(name='IssuingAuthority', example='null'),
        issuingAuthorityConfidence?: double(name='IssuingAuthorityConfidence', example='0.92'),
        issuingAuthorityPosition?: [ long ](name='IssuingAuthorityPosition'),
        lastName?: string(name='LastName', example='null'),
        lastNameConfidence?: double(name='LastNameConfidence', example='0.92'),
        lastNamePosition?: [ long ](name='LastNamePosition'),
        nationalityCode?: string(name='NationalityCode', example='JP'),
        nationalityCodeConfidence?: double(name='NationalityCodeConfidence', example='0.92'),
        nationalityCodePosition?: [ long ](name='NationalityCodePosition'),
        normalizedDateOfBirth?: string(name='NormalizedDateOfBirth', example='2009/01/16'),
        normalizedExpirationDate?: string(name='NormalizedExpirationDate', example='2027/01/16'),
        normalizedIssuedDate?: string(name='NormalizedIssuedDate', example='2023/01/16'),
        normalizedNationalityCode?: string(name='NormalizedNationalityCode', example='JPN'),
        normalizedSex?: string(name='NormalizedSex', example='M'),
        sex?: string(name='Sex', example='Male'),
        sexConfidence?: double(name='SexConfidence', example='0.92'),
        sexPosition?: [ long ](name='SexPosition'),
      }(name='OcrResultData'),
    }(name='OcrResult'),
    unrepeatResult?: {
      cardImageResult?: {
        cardImageResultData?: {
          dbname?: string(name='Dbname', example='cardFace'),
          entityId?: string(name='EntityId', example='990614535008'),
          extraData?: string(name='ExtraData', example='null'),
          score?: double(name='Score', example='99.72'),
        }(name='CardImageResultData'),
        code?: string(name='Code', example='0'),
        message?: string(name='Message', example='null'),
      }(name='CardImageResult'),
      portraitImageResult?: {
        code?: string(name='Code', example='0'),
        message?: string(name='Message', example='null'),
        portraitImageResultData?: {
          dbname?: string(name='Dbname', example='cardFace'),
          entityId?: string(name='EntityId', example='990614535008'),
          extraData?: string(name='ExtraData', example='null'),
          score?: double(name='Score', example='99.72'),
        }(name='PortraitImageResultData'),
      }(name='PortraitImageResult'),
    }(name='UnrepeatResult'),
  }(name='Data'),
  httpCode?: long(name='HttpCode', example='200'),
  message?: string(name='Message', example='null'),
  ok?: boolean(name='Ok', example='true'),
  requestId?: string(name='RequestId', example='4D93120B-9A81-11F5-8307-B746390C644D'),
  status?: string(name='Status', example='SUCCESS'),
}

model IdDetectOcrCompareFacesResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: IdDetectOcrCompareFacesResponseBody(name='body'),
}

async function idDetectOcrCompareFacesWithOptions(request: IdDetectOcrCompareFacesRequest, headers: map[string]string, runtime: Util.RuntimeOptions): IdDetectOcrCompareFacesResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.OCR)) {
    body['OCR'] = request.OCR;
  }
  if (!Util.isUnset(request.unrepeat)) {
    body['Unrepeat'] = request.unrepeat;
  }
  if (!Util.isUnset(request.cardDetect)) {
    body['cardDetect'] = request.cardDetect;
  }
  if (!Util.isUnset(request.countryCode)) {
    body['countryCode'] = request.countryCode;
  }
  if (!Util.isUnset(request.documentType)) {
    body['documentType'] = request.documentType;
  }
  if (!Util.isUnset(request.faceCompare)) {
    body['faceCompare'] = request.faceCompare;
  }
  if (!Util.isUnset(request.imageAType)) {
    body['imageAType'] = request.imageAType;
  }
  if (!Util.isUnset(request.imageBType)) {
    body['imageBType'] = request.imageBType;
  }
  if (!Util.isUnset(request.imageDataA)) {
    body['imageDataA'] = request.imageDataA;
  }
  if (!Util.isUnset(request.imageDataB)) {
    body['imageDataB'] = request.imageDataB;
  }
  if (!Util.isUnset(request.imageUrlA)) {
    body['imageUrlA'] = request.imageUrlA;
  }
  if (!Util.isUnset(request.imageUrlB)) {
    body['imageUrlB'] = request.imageUrlB;
  }
  if (!Util.isUnset(request.portraitImageData)) {
    body['portraitImageData'] = request.portraitImageData;
  }
  if (!Util.isUnset(request.portraitImageUrl)) {
    body['portraitImageUrl'] = request.portraitImageUrl;
  }
  if (!Util.isUnset(request.qualityControl)) {
    body['qualityControl'] = request.qualityControl;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'IdDetectOcrCompareFaces',
    version = '2023-01-12',
    protocol = 'HTTPS',
    pathname = `/id_detect_ocr_compare_faces`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function idDetectOcrCompareFaces(request: IdDetectOcrCompareFacesRequest): IdDetectOcrCompareFacesResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return idDetectOcrCompareFacesWithOptions(request, headers, runtime);
}

model IdDetectionAndScanDocumentRequest {
  countryCode?: string(name='countryCode', example='JPN'),
  documentType?: string(name='documentType', example='IDENTITY_CARD'),
  imageAType?: string(name='imageAType', example='pic'),
  imageBType?: string(name='imageBType', example='pic'),
  imageDataA?: string(name='imageDataA', example='/9j/4AAQSkZJRgABAQEAXgBeAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL******'),
  imageDataB?: string(name='imageDataB', example='/9j/4AAQSkZJRgABAQEAXgBeAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL******'),
  imageUrlA?: string(name='imageUrlA', example='https://your_test_image.jpg'),
  imageUrlB?: string(name='imageUrlB', example='https://your_test_image.jpg'),
}

model IdDetectionAndScanDocumentResponseBody = {
  code?: string(name='Code', example='0'),
  data?: {
    idDetectResult?: {
      antiSpoofingResult?: {
        passed?: boolean(name='Passed', example='false'),
        risks?: [ string ](name='Risks'),
      }(name='AntiSpoofingResult'),
      countryCode?: string(name='CountryCode', example='JPN'),
      detectionResult?: {
        cardRectangle?: [ long ](name='CardRectangle'),
        height?: long(name='Height', example='382'),
        portraitRectangle?: [ long ](name='PortraitRectangle'),
        width?: long(name='Width', example='600'),
      }(name='DetectionResult'),
      documentType?: string(name='DocumentType', example='IDENTITY_CARD'),
      passed?: boolean(name='Passed', example='false'),
      warning?: [ string ](name='Warning'),
    }(name='IdDetectResult'),
    ocrResult?: {
      address?: string(name='Address', example='null'),
      addressConfidence?: double(name='AddressConfidence', example='0.92'),
      addressPosition?: [ long ](name='AddressPosition'),
      dateOfBirth?: string(name='DateOfBirth', example='2009-01-16'),
      dateOfBirthConfidence?: double(name='DateOfBirthConfidence', example='0.92'),
      dateOfBirthPosition?: [ long ](name='DateOfBirthPosition'),
      documentNumber?: string(name='DocumentNumber', example='null'),
      documentNumber2?: string(name='DocumentNumber2', example='null'),
      documentNumber2Confidence?: double(name='DocumentNumber2Confidence', example='0.92'),
      documentNumber2Position?: [ long ](name='DocumentNumber2Position'),
      documentNumberConfidence?: double(name='DocumentNumberConfidence', example='0.92'),
      documentNumberPosition?: [ long ](name='DocumentNumberPosition'),
      expirationDate?: string(name='ExpirationDate', example='2027.01.16'),
      expirationDateConfidence?: double(name='ExpirationDateConfidence', example='0.92'),
      expirationDatePosition?: [ long ](name='ExpirationDatePosition'),
      firstName?: string(name='FirstName', example='null'),
      firstNameConfidence?: double(name='FirstNameConfidence', example='0.92'),
      firstNamePosition?: [ long ](name='FirstNamePosition'),
      fullName?: string(name='FullName', example='null'),
      fullNameConfidence?: double(name='FullNameConfidence', example='0.92'),
      fullNamePosition?: [ long ](name='FullNamePosition'),
      issuedDate?: string(name='IssuedDate', example='Jan 16 2023'),
      issuedDateConfidence?: double(name='IssuedDateConfidence', example='0.92'),
      issuedDatePosition?: [ long ](name='IssuedDatePosition'),
      issuingAuthority?: string(name='IssuingAuthority', example='null'),
      issuingAuthorityConfidence?: double(name='IssuingAuthorityConfidence', example='0.92'),
      issuingAuthorityPosition?: [ long ](name='IssuingAuthorityPosition'),
      lastName?: string(name='LastName', example='null'),
      lastNameConfidence?: double(name='LastNameConfidence', example='0.92'),
      lastNamePosition?: [ long ](name='LastNamePosition'),
      nationalityCode?: string(name='NationalityCode', example='JP'),
      nationalityCodeConfidence?: double(name='NationalityCodeConfidence', example='0.92'),
      nationalityCodePosition?: [ long ](name='NationalityCodePosition'),
      normalizedDateOfBirth?: string(name='NormalizedDateOfBirth', example='2009/01/16'),
      normalizedExpirationDate?: string(name='NormalizedExpirationDate', example='2027/01/16'),
      normalizedIssuedDate?: string(name='NormalizedIssuedDate', example='2023/01/16'),
      normalizedNationalityCode?: string(name='NormalizedNationalityCode', example='JPN'),
      normalizedSex?: string(name='NormalizedSex', example='M'),
      sex?: string(name='Sex', example='Male'),
      sexConfidence?: double(name='SexConfidence', example='0.92'),
      sexPosition?: [ long ](name='SexPosition'),
    }(name='OcrResult'),
  }(name='Data'),
  httpCode?: long(name='HttpCode', example='200'),
  message?: string(name='Message', example='null'),
  ok?: boolean(name='Ok', example='true'),
  requestId?: string(name='RequestId', example='4D93120B-9A81-11F5-8307-B746390C644D'),
  status?: string(name='Status', example='SUCCESS'),
}

model IdDetectionAndScanDocumentResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: IdDetectionAndScanDocumentResponseBody(name='body'),
}

async function idDetectionAndScanDocumentWithOptions(request: IdDetectionAndScanDocumentRequest, headers: map[string]string, runtime: Util.RuntimeOptions): IdDetectionAndScanDocumentResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.countryCode)) {
    body['countryCode'] = request.countryCode;
  }
  if (!Util.isUnset(request.documentType)) {
    body['documentType'] = request.documentType;
  }
  if (!Util.isUnset(request.imageAType)) {
    body['imageAType'] = request.imageAType;
  }
  if (!Util.isUnset(request.imageBType)) {
    body['imageBType'] = request.imageBType;
  }
  if (!Util.isUnset(request.imageDataA)) {
    body['imageDataA'] = request.imageDataA;
  }
  if (!Util.isUnset(request.imageDataB)) {
    body['imageDataB'] = request.imageDataB;
  }
  if (!Util.isUnset(request.imageUrlA)) {
    body['imageUrlA'] = request.imageUrlA;
  }
  if (!Util.isUnset(request.imageUrlB)) {
    body['imageUrlB'] = request.imageUrlB;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'IdDetectionAndScanDocument',
    version = '2023-01-12',
    protocol = 'HTTPS',
    pathname = `/id_detection_and_scan_document`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function idDetectionAndScanDocument(request: IdDetectionAndScanDocumentRequest): IdDetectionAndScanDocumentResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return idDetectionAndScanDocumentWithOptions(request, headers, runtime);
}

model ScanDocumentRequest {
  countryCode?: string(name='countryCode', description='The country or region code of the certificate. Specify the code in the ISO 3166 alpha-3 format.', example='JPN'),
  documentType?: string(name='documentType', description='The type of the certificate.

Valid values:

*   IDENTITY_CARD

    <!-- -->

    <!-- -->

    <!-- -->

*   DRIVER_LICENSE

    <!-- -->

    <!-- -->

    <!-- -->

*   RESIDENCE_CARD

    <!-- -->

    <!-- -->

    <!-- -->

*   PASSPORT

    <!-- -->

    <!-- -->

    <!-- -->', example='IDENTITY_CARD'),
  imageAType?: string(name='imageAType', description='Indicates whether the uploaded front-side image is in an image format or PDF format. The default value is pic.', example='pic'),
  imageBType?: string(name='imageBType', description='Indicates whether the uploaded back-side image is in an image format or PDF format. The default value is pic.', example='pic'),
  imageDataA?: string(name='imageDataA', description='The Base64-encoded front-side image of the certificate. Either this parameter or the imageUrlA parameter must be specified.', example='/9j/4AAQSkZJRgABAQEAXgBeAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL******'),
  imageDataB?: string(name='imageDataB', description='The Base64-encoded back-side image of the certificate.', example='/9j/4AAQSkZJRgABAQEAXgBeAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL******'),
  imageUrlA?: string(name='imageUrlA', description='The URL of the front-side image of the certificate. Either this parameter or the imageDataA parameter must be specified.', example='https://your_test_image.jpg'),
  imageUrlB?: string(name='imageUrlB', description='The URL of the back-side image of the certificate.', example='https://your_test_image.jpg'),
}

model ScanDocumentResponseBody = {
  code?: string(name='Code', description='The error code. A value of 0 indicates that the request is successful.', example='0'),
  data?: {
    address?: string(name='Address', description='The address.', example='null'),
    addressConfidence?: double(name='AddressConfidence', description='The confidence level of the recognized Address.', example='0.92'),
    addressPosition?: [ long ](name='AddressPosition', description='The coordinates of four vertices of the Address field area in the clockwise sequence: the upper left, upper right, lower right, and lower left.'),
    dateOfBirth?: string(name='DateOfBirth', description='The date of birth.', example='2009-01-16'),
    dateOfBirthConfidence?: double(name='DateOfBirthConfidence', description='The confidence level of the recognized DateOfBirth.', example='0.92'),
    dateOfBirthPosition?: [ long ](name='DateOfBirthPosition', description='The coordinates of four vertices of the DateOfBirth field area in the clockwise sequence: the upper left, upper right, lower right, and lower left.'),
    documentNumber?: string(name='DocumentNumber', description='The certificate number.', example='null'),
    documentNumber2?: string(name='DocumentNumber2', description='The secondary certificate number.', example='null'),
    documentNumber2Confidence?: double(name='DocumentNumber2Confidence', description='The confidence level of the recognized DocumentNumber2.', example='0.92'),
    documentNumber2Position?: [ long ](name='DocumentNumber2Position', description='The coordinates of four vertices of the DocumentNumber2 field area in the clockwise sequence: the upper left, upper right, lower right, and lower left.'),
    documentNumberConfidence?: double(name='DocumentNumberConfidence', description='The confidence level of the recognized DocumentNumber.', example='0.92'),
    documentNumberPosition?: [ long ](name='DocumentNumberPosition', description='The coordinates of four vertices of the DocumentNumber field area in the clockwise sequence: the upper left, upper right, lower right, and lower left.'),
    expirationDate?: string(name='ExpirationDate', description='The expiration date of the certificate.', example='2027.01.16'),
    expirationDateConfidence?: double(name='ExpirationDateConfidence', description='The confidence level of the recognized ExpirationDate.', example='0.92'),
    expirationDatePosition?: [ long ](name='ExpirationDatePosition', description='The coordinates of four vertices of the ExpirationDate field area in the clockwise sequence: the upper left, upper right, lower right, and lower left.'),
    firstName?: string(name='FirstName', description='The first name.', example='null'),
    firstNameConfidence?: double(name='FirstNameConfidence', description='The confidence level of the recognized FirstName field.', example='0.92'),
    firstNamePosition?: [ long ](name='FirstNamePosition', description='The coordinates of four vertices of the FirstName field area in the clockwise sequence: the upper left, upper right, lower right, and lower left.'),
    fullName?: string(name='FullName', description='The full name.', example='null'),
    fullNameConfidence?: double(name='FullNameConfidence', description='The confidence level of the recognized FullName.', example='0.92'),
    fullNamePosition?: [ long ](name='FullNamePosition', description='The coordinates of four vertices of the FullName field area in the clockwise sequence: the upper left, upper right, lower right, and lower left.'),
    issuedDate?: string(name='IssuedDate', description='The date of issue.', example='Jan 16 2023'),
    issuedDateConfidence?: double(name='IssuedDateConfidence', description='The confidence level of the recognized IssuedDate.', example='0.92'),
    issuedDatePosition?: [ long ](name='IssuedDatePosition', description='The coordinates of four vertices of the IssuedDate field area in the clockwise sequence: the upper left, upper right, lower right, and lower left.'),
    issuingAuthority?: string(name='IssuingAuthority', description='The organization that issued the certificate.', example='null'),
    issuingAuthorityConfidence?: double(name='IssuingAuthorityConfidence', description='The confidence level of the recognized IssuingAuthority.', example='0.92'),
    issuingAuthorityPosition?: [ long ](name='IssuingAuthorityPosition', description='The coordinates of four vertices of the IssuingAuthority field area in the clockwise sequence: the upper left, upper right, lower right, and lower left.'),
    lastName?: string(name='LastName', description='The last name.', example='null'),
    lastNameConfidence?: double(name='LastNameConfidence', description='The confidence level of the recognized LastName.', example='0.92'),
    lastNamePosition?: [ long ](name='LastNamePosition', description='The coordinates of four vertices of the LastName field area in the clockwise sequence: the upper left, upper right, lower right, and lower left.'),
    nationalityCode?: string(name='NationalityCode', description='The country or region code on the certificate.', example='JP'),
    nationalityCodeConfidence?: double(name='NationalityCodeConfidence', description='The confidence level of the recognized NationalityCode.', example='0.92'),
    nationalityCodePosition?: [ long ](name='NationalityCodePosition', description='The coordinates of four vertices of the NationalityCode field area in the clockwise sequence: the upper left, upper right, lower right, and lower left.'),
    normalizedDateOfBirth?: string(name='NormalizedDateOfBirth', description='The date of birth in the format of YYYY/MM/dd.', example='2009/01/16'),
    normalizedExpirationDate?: string(name='NormalizedExpirationDate', description='The expiration date in the format of YYYY/MM/dd.', example='2027/01/16'),
    normalizedIssuedDate?: string(name='NormalizedIssuedDate', description='The date of issue in the format of YYYY/MM/dd.', example='2023/01/16'),
    normalizedNationalityCode?: string(name='NormalizedNationalityCode', description='The country or region code in the ISO 3166 alpha-3 format.', example='JPN'),
    normalizedSex?: string(name='NormalizedSex', description='The gender.

Valid values:

*   null

    <!-- -->

    <!-- -->

    <!-- -->

*   F

    <!-- -->

    :

    <!-- -->

    female

    <!-- -->

*   M

    <!-- -->

    :

    <!-- -->

    male

    <!-- -->', example='M'),
    sex?: string(name='Sex', description='The gender.', example='Male'),
    sexConfidence?: double(name='SexConfidence', description='The confidence level of the recognized Sex.', example='0.92'),
    sexPosition?: [ long ](name='SexPosition', description='The coordinates of four vertices of the Sex field area in the clockwise sequence: the upper left, upper right, lower right, and lower left.'),
  }(name='Data', description='The returned data.'),
  httpCode?: long(name='HttpCode', description='The HTTP status code.', example='200'),
  message?: string(name='Message', description='The error messages.', example='null'),
  ok?: boolean(name='Ok', description='Indicates whether the request is successful.

Valid values:

*   true

    <!-- -->

    <!-- -->

    <!-- -->

*   false

    <!-- -->

    <!-- -->

    <!-- -->', example='true'),
  requestId?: string(name='RequestId', description='The ID of the request.', example='4D93120B-9A81-11F5-8307-B746390C644D'),
  status?: string(name='Status', description='The status of the request.', example='SUCCESS'),
}

model ScanDocumentResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ScanDocumentResponseBody(name='body'),
}

/**
  * After you upload the front-side image and back-side image (optional) of the certificate, the system returns the structured OCR results.
  * ### Limits
  * *   Format: JPEG or PNG.
  * *   Resolution: The length of an image is no greater than 4000 pixels, and the width is no smaller than 400 pixels. Recommended size: 1024\\*768.
  * *   Size: the size of a single image. Valid values: \\[4KB, 6MB].
  * ### Data protocol
  * *   Request: application/json.
  * *   Response: application/json.
  * *   Binary data: Base64.
  *
  * @param request ScanDocumentRequest
  * @param headers map
  * @param runtime runtime options for this request RuntimeOptions
  * @return ScanDocumentResponse
 */
async function scanDocumentWithOptions(request: ScanDocumentRequest, headers: map[string]string, runtime: Util.RuntimeOptions): ScanDocumentResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.countryCode)) {
    body['countryCode'] = request.countryCode;
  }
  if (!Util.isUnset(request.documentType)) {
    body['documentType'] = request.documentType;
  }
  if (!Util.isUnset(request.imageAType)) {
    body['imageAType'] = request.imageAType;
  }
  if (!Util.isUnset(request.imageBType)) {
    body['imageBType'] = request.imageBType;
  }
  if (!Util.isUnset(request.imageDataA)) {
    body['imageDataA'] = request.imageDataA;
  }
  if (!Util.isUnset(request.imageDataB)) {
    body['imageDataB'] = request.imageDataB;
  }
  if (!Util.isUnset(request.imageUrlA)) {
    body['imageUrlA'] = request.imageUrlA;
  }
  if (!Util.isUnset(request.imageUrlB)) {
    body['imageUrlB'] = request.imageUrlB;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ScanDocument',
    version = '2023-01-12',
    protocol = 'HTTPS',
    pathname = `/scan_document`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
  * After you upload the front-side image and back-side image (optional) of the certificate, the system returns the structured OCR results.
  * ### Limits
  * *   Format: JPEG or PNG.
  * *   Resolution: The length of an image is no greater than 4000 pixels, and the width is no smaller than 400 pixels. Recommended size: 1024\\*768.
  * *   Size: the size of a single image. Valid values: \\[4KB, 6MB].
  * ### Data protocol
  * *   Request: application/json.
  * *   Response: application/json.
  * *   Binary data: Base64.
  *
  * @param request ScanDocumentRequest
  * @return ScanDocumentResponse
 */
async function scanDocument(request: ScanDocumentRequest): ScanDocumentResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return scanDocumentWithOptions(request, headers, runtime);
}

model VerifyDocumentRequest {
  countryCode?: string(name='countryCode', example='JPN'),
  detThickness?: boolean(name='detThickness', example='false'),
  documentType?: string(name='documentType', example='IDENTITY_CARD'),
  imageAType?: string(name='imageAType', example='pic'),
  imageBType?: string(name='imageBType', example='pic'),
  imageCType?: string(name='imageCType', example='pic'),
  imageDataA?: string(name='imageDataA', example='/9j/4AAQSkZJRgABAQEAXgBeAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL******'),
  imageDataB?: string(name='imageDataB', example='/9j/4AAQSkZJRgABAQEAXgBeAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL******'),
  imageDataC?: string(name='imageDataC', example='/9j/4AAQSkZJRgABAQEAXgBeAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL******'),
  imageUrlA?: string(name='imageUrlA', example='https://your_test_image.jpg'),
  imageUrlB?: string(name='imageUrlB', example='https://your_test_image.jpg'),
  imageUrlC?: string(name='imageUrlC', example='https://your_test_image.jpg'),
}

model VerifyDocumentResponseBody = {
  code?: string(name='Code', example='0'),
  data?: {
    antiSpoofingResult?: {
      passed?: boolean(name='Passed', example='true'),
      risks?: [ string ](name='Risks'),
    }(name='AntiSpoofingResult'),
    countryCode?: string(name='CountryCode', example='JPN'),
    detectionResult?: {
      cardRectangle?: [ long ](name='CardRectangle'),
      height?: long(name='Height', example='382'),
      portraitRectangle?: [ long ](name='PortraitRectangle'),
      width?: long(name='Width', example='600'),
    }(name='DetectionResult'),
    documentType?: string(name='DocumentType', example='IDENTITY_CARD'),
    passed?: boolean(name='Passed', example='true'),
  }(name='Data'),
  httpCode?: long(name='HttpCode', example='200'),
  message?: string(name='Message', example='null'),
  ok?: boolean(name='Ok', example='true'),
  requestId?: string(name='RequestId', example='4D93120B-9A81-11F5-8307-B746390C644D'),
  status?: string(name='Status', example='SUCCESS'),
}

model VerifyDocumentResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: VerifyDocumentResponseBody(name='body'),
}

async function verifyDocumentWithOptions(request: VerifyDocumentRequest, headers: map[string]string, runtime: Util.RuntimeOptions): VerifyDocumentResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.countryCode)) {
    body['countryCode'] = request.countryCode;
  }
  if (!Util.isUnset(request.detThickness)) {
    body['detThickness'] = request.detThickness;
  }
  if (!Util.isUnset(request.documentType)) {
    body['documentType'] = request.documentType;
  }
  if (!Util.isUnset(request.imageAType)) {
    body['imageAType'] = request.imageAType;
  }
  if (!Util.isUnset(request.imageBType)) {
    body['imageBType'] = request.imageBType;
  }
  if (!Util.isUnset(request.imageCType)) {
    body['imageCType'] = request.imageCType;
  }
  if (!Util.isUnset(request.imageDataA)) {
    body['imageDataA'] = request.imageDataA;
  }
  if (!Util.isUnset(request.imageDataB)) {
    body['imageDataB'] = request.imageDataB;
  }
  if (!Util.isUnset(request.imageDataC)) {
    body['imageDataC'] = request.imageDataC;
  }
  if (!Util.isUnset(request.imageUrlA)) {
    body['imageUrlA'] = request.imageUrlA;
  }
  if (!Util.isUnset(request.imageUrlB)) {
    body['imageUrlB'] = request.imageUrlB;
  }
  if (!Util.isUnset(request.imageUrlC)) {
    body['imageUrlC'] = request.imageUrlC;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'VerifyDocument',
    version = '2023-01-12',
    protocol = 'HTTPS',
    pathname = `/verify_document`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function verifyDocument(request: VerifyDocumentRequest): VerifyDocumentResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return verifyDocumentWithOptions(request, headers, runtime);
}

